<?php



require_once("functions.php");
$db = connect_db();

if (isset($argv[1])) {
	$lang = $argv[1];
} else
	die ("Need parameters: <language> ");

function escape($str)
{
	$chars = array ('\\', '\'');
	foreach ($chars as $c) {
		$str = str_replace($c, '\\' . $c, $str);
	}
	return  $str ;
}



$hdr = file_get_contents('header.inc');
$ftr = file_get_contents('footer.inc');


$lang = mysql_real_escape_string($lang);
$sql = "select id from languages  where language like '$lang'";
$res = mysql_query($sql, $db);

if ($res == FALSE)
	die (mysql_error());
$row = mysql_fetch_array($res);
if ($row === FALSE)
	die ("Unknown language");
$lang = $row[0];


$sql = "select * from fields join `values` on fields.id = `values`.variable_id where language_id = $lang";

$res = mysql_query($sql, $db);
if ($res == FALSE)
	die (mysql_error());


echo $hdr;

echo "\n";

while (($row = mysql_fetch_array($res)) !== FALSE) {
	echo '$LN[\'' . $row['variable']. '\']';
	if ($row['extra_variable'] != '')
		echo '[\'' . $row['extra_variable'] . '\']';
	$val = $row['value'];
	$val2 = $row['value2'];
//	if (strstr($val2, 'http')) echo "$val $val2\n";
	if ($val2 == '')
		echo ' = \'' . addcslashes($val, "'") . "'\n";
	else 
		echo ' = array(\'' . addcslashes($val, "'") . ', \'' . addcslashes($val2, "'") . '\');' . "\n";

}

echo "\n";
echo $ftr;

?>
